<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
    <script>
        var arr = [4,1,2,1,2];
        var containsDuplicate = function(nums) {
            for (let i=0;i<nums.length;i++){
                if (nums.indexOf(nums[i]) == nums.lastIndexOf(nums[i])) {
                    return nums[i]
                }
            }
        };

        console.log(containsDuplicate(arr));

    </script>
</body>
</html>